﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using Shsc.Net.FrameWork.Common.SysException;
using Shsc.Net.FrameWork.Common.Log;

namespace Shsc.Net.FrameWork.Web
{
    public abstract class BasePage : Page
    {
        /// <summary>
        /// Log4NetLogger
        /// </summary>
        protected Log4NetLogger logger;

        /// <summary>
        /// 創建Log對象
        /// </summary>
        protected abstract void CreateLogger();

        /// <summary>
        /// 畫面初期化
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            CreateLogger();
        }

        /// <summary>
        /// 畫面處理
        /// </summary>
        /// <param name="e"></param>
        protected override void OnError(EventArgs e)
        {
            base.OnError(e);
            Exception ex = Server.GetLastError();
            //記錄異常信息
            logger.Fatal(ex);
            if (ex is BusinessException)
            {
                //處理業務異常
                //TODO
            }
            else
            {
                //未處理的異常繼續拋出
                throw ex;
            }
        }
    }
}
